﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Lswweb.Domain;
using Lswweb.Model;

namespace Lswweb.Controls
{
    public class OrderShow : SkinnedWebControl
    {
        private Label lbOrderId;
        private Label lbLogisticsPrices;
        private Label lbProductPrices;
        private Label lbPreferentialPrices;
        private Label lbTotalPrices;
        private Label lbName;
        private Label lbPhone;
        private Label lbMobile;
        private Label lbEmail;
        private Label lbAddress;
        private Label lbZip;
        private Label lbDateCreated;
        private Label lbStatus;
        private Label lbRemark;
        private Label lbLtsType;

        private Label lbBankName;
        private Label lbBankAccounts;
        private Label lbMoneyType;
        private Label lbAmount;
        private Label lbPaymentDates;
        private Label lbPaymentRemark;
        private Label lbPaymentDateCreated;

        private Label lbLogisticsName;
        private Label lbTrackingNumber;
        private Label lbSendDates;
        private Label lbLogisticsDateCreated;
        private Label lbLogisticsRemark;

        protected override void InitializeSkin(Control skin)
        {
            lbOrderId = (Label)skin.FindControl("lbOrderId");
            lbLogisticsPrices = (Label)skin.FindControl("lbLogisticsPrices");
            lbProductPrices = (Label)skin.FindControl("lbProductPrices");
            lbPreferentialPrices = (Label)skin.FindControl("lbPreferentialPrices");
            lbTotalPrices = (Label)skin.FindControl("lbTotalPrices");
            lbName = (Label)skin.FindControl("lbName");
            lbPhone = (Label)skin.FindControl("lbPhone");
            lbMobile = (Label)skin.FindControl("lbMobile");
            lbEmail = (Label)skin.FindControl("lbEmail");
            lbAddress = (Label)skin.FindControl("lbAddress");
            lbZip = (Label)skin.FindControl("lbZip");
            lbDateCreated = (Label)skin.FindControl("lbDateCreated");
            lbStatus = (Label)skin.FindControl("lbStatus");
            lbRemark = (Label)skin.FindControl("lbRemark");
            lbLtsType = (Label)skin.FindControl("lbLtsType");

            lbBankName = (Label)skin.FindControl("lbBankName");
            lbBankAccounts = (Label)skin.FindControl("lbBankAccounts");
            lbMoneyType = (Label)skin.FindControl("lbMoneyType");
            lbAmount = (Label)skin.FindControl("lbAmount");
            lbPaymentDates = (Label)skin.FindControl("lbPaymentDates");
            lbPaymentRemark = (Label)skin.FindControl("lbPaymentRemark");
            lbPaymentDateCreated = (Label)skin.FindControl("lbPaymentDateCreated");

            lbLogisticsName = (Label)skin.FindControl("lbLogisticsName");
            lbTrackingNumber = (Label)skin.FindControl("lbTrackingNumber");
            lbSendDates = (Label)skin.FindControl("lbSendDates");
            lbLogisticsDateCreated = (Label)skin.FindControl("lbLogisticsDateCreated");
            lbLogisticsRemark = (Label)skin.FindControl("lbLogisticsRemark");


            if (Info == null)
                return;

            if (lbOrderId != null)
                lbOrderId.Text = Info.Id.ToString();

            if (lbLogisticsPrices != null)
                lbLogisticsPrices.Text =CurrencyServices.ForamtPrice(Info.LogisticsPrices);

            if (lbProductPrices != null)
                lbProductPrices.Text = CurrencyServices.ForamtPrice(Info.ProductPrices);

            if (lbPreferentialPrices != null)
                lbPreferentialPrices.Text = CurrencyServices.ForamtPrice(Info.PreferentialPrices);

            if (lbTotalPrices != null)
                lbTotalPrices.Text = CurrencyServices.ForamtPrice(Info.TotalPrices);

            if (lbName != null)
                lbName.Text = Info.Name;

            if (lbPhone != null)
                lbPhone.Text = Info.Phone;

            if (lbMobile != null)
                lbMobile.Text = Info.Mobile;

            if (lbAddress != null)
                lbAddress.Text = Info.Address + "," + TreeTables.Cities.GetCategoryName(Info.CityId);

            if (lbZip != null)
                lbZip.Text = Info.Zip;

            if (lbDateCreated != null)
                lbDateCreated.Text = Info.DateCreated.ToString(SiteSettings.Settings.DateTimeFormat);

            if (lbStatus != null)
                lbStatus.Text = Enum<OrderStatus>.GetEnumStr(Info.Status);

            if (lbRemark != null)
                lbRemark.Text = Info.Remark;

            if (lbLtsType != null)
                lbLtsType.Text = Info.Logistics.Name;

            if (Info.Payment != null)
            {
                if (lbBankName != null)
                    lbBankName.Text = Info.Payment.BankName;

                if (lbBankAccounts != null)
                    lbBankAccounts.Text = Info.Payment.BankAccounts;

                if (lbMoneyType != null)
                    lbMoneyType.Text = Info.Payment.CurrencyType;

                if (lbAmount != null)
                    lbAmount.Text = Info.Payment.Amount.ToString();

                if (lbPaymentDates != null)
                    lbPaymentDates.Text = Info.Payment.Dates.ToString(SiteSettings.Settings.DateTimeFormat);

                if (lbPaymentRemark != null)
                    lbPaymentRemark.Text = Info.Payment.Remark;

                if (lbPaymentDateCreated != null)
                    lbPaymentDateCreated.Text = Info.Payment.DateCreated.ToString(SiteSettings.Settings.DateTimeFormat);
            }

            if (Info.Logistics != null)
            {
                if (lbLogisticsName != null)
                    lbLogisticsName.Text = Info.Logistics.Name;

                if (lbTrackingNumber != null)
                    lbTrackingNumber.Text = Info.Logistics.TrackingNumber;

                if (lbSendDates != null && Info.Logistics.SendDates!=null)
                    lbSendDates.Text = ((DateTime)Info.Logistics.SendDates).ToString(SiteSettings.Settings.DateTimeFormat);

                if (lbLogisticsDateCreated != null)
                    lbLogisticsDateCreated.Text = Info.Logistics.DateCreated.ToString(SiteSettings.Settings.DateTimeFormat);

                if (lbLogisticsRemark != null)
                    lbLogisticsRemark.Text = Info.Logistics.Remark;
            }
        }

        public OrderInfo Info
        {
            get { return Orders.GetOrder(SiteContext.Current.Id); }
        }

        protected override string DefaultSkinFilename
        {
            get { return "Order/OrderShow.ascx"; }
        }
    }
}
